package com.ccc.ka;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.ccc.ka.util.BaseController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;

@SpringBootTest
public class KAGenerate {
    @Value("${spring.datasource.url}")
    String springDatasourceUrl;

    String path = System.getProperty("user.dir");

    @Test
    public void autoGenerate() {

        FastAutoGenerator.create(springDatasourceUrl, "ka" , "ka")
                .globalConfig(builder -> {
                    builder.author("ccc")
                            .enableSwagger()
                            .fileOverride()
                            .outputDir(path + "/src/main/java/");
                })
                .packageConfig(builder -> {
                    builder.parent("com.ccc.ka")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, path + "/src/main/resources/mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude("ka_records_type")
                            .addTablePrefix("ka_");
                })
                .strategyConfig(builder -> {
                    builder.controllerBuilder()
                            .superClass(BaseController.class)
                            .enableRestStyle();
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableLombok();
                })
                .templateConfig(builder -> {
                    builder.controller("templates/controller.java.vm");
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
    @Test
    public void other(){
        String currentPath=System.getProperty("user.dir");
        System.out.println(currentPath);
    }
}